import java.util.TreeSet;

public class Q1 {

  public static class Point implements Comparable<Point>{

    public double x;

    public double y;

    // compareTo defines the order of Point in the MaxHeap
    public int compareTo(Point o) {
    	double d1 = x * x + y * y;
    	double d2 = o.x * o.x + o.y * o.y;
    	
    	return Double.compare(d2, d1);
    }
    
    public String toString() {
    	return "(" + x + ", " + y + ")";
    }
  } 

  public static Point[] closestk( Point  myList[], int k ) {
	  if (null == myList || k <= 0 || k > myList.length) {
		  return null;
	  }
	  // Use TreeSet to imitate a heap
	  TreeSet<Point> maxHeap = new TreeSet<Point>();
	  int i = 0;

	  // Build the heap of size k
	  for (i = 0; i < k; i++) {
		  maxHeap.add(myList[i]);
	  }
	  
	  // Everytime add a Point into the heap, remove the largest one.
	  for (i = k; i < myList.length; i++) {
		  maxHeap.add(myList[i]);
		  maxHeap.remove(maxHeap.first());
	  }
	  
	  // The remaining elements are the answer.
	  Point[] result = new Point[k];
	  for (i = 0; i < k; i++) {
		  result[i] = maxHeap.first();
		  maxHeap.remove(maxHeap.first());
	  }
	  return result;
  }

  
  public static void main(String[] args) {
	  int n = 10;
	  int k = 5;
	  Point[] points = new Point[n];
	for (int i = 0; i < n; i++) {
		Point p = new Point();
		p.x = i;
		p.y = i;
		points[i] = p;
	}
	
	Point[] result = closestk(points, k);
	for (int i = 0; i < result.length; i++) {
		System.out.println(result[i]);
	}
  }
}